﻿using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using LiftHub.Data.LedgerModels;

namespace LiftHub.Controls;

public partial class AddLedgerControl : UserControl
{
    public AddLedgerControl(IEnumerable<CategoryModel> models)
    {
        InitializeComponent();
        Category = this.FindControl<ComboBox>("Category");
        Category!.ItemsSource = models.Select(x => x.CategoryName);
    }

    public LedgerModel? Done()
    {
        if (string.IsNullOrEmpty(Name.Text)) return null;
        return new LedgerModel(Name.Text, Amount.Value!.Value, Category.SelectedItem as string,
            CreateTime.SelectedDate.ToString());
    }
}